package com.cjbdi.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.cjbdi.entity.Fypz;
import com.cjbdi.entity.GongGao;
import com.cjbdi.entity.UserGonggao;
import com.cjbdi.entity.UserInfo;

import java.util.List;

@Repository
public interface UserGonggaoRepository extends JpaRepository<UserGonggao, Long> {
	@Transactional
	@Modifying(clearAutomatically = true)
	@Query(value = "delete from user_gonggao where gonggaoid=:gonggaoid", nativeQuery = true) // 原生SQL
	Integer delete(@Param("gonggaoid") int gonggaoid);
	
	@Query(value = "select * from user_gonggao where userip=:userip and gonggaoid=:gonggaoid", nativeQuery = true)
    List<UserGonggao> getGonggaobyIpAndid(@Param("userip")String userip,@Param("gonggaoid")int gonggaoid);	
	
	@Query(value = "select userip,content,status,title,user_gonggao.gonggaoid from user_gonggao,gonggao where user_gonggao.userip=:ip and user_gonggao.gonggaoid=gonggao.id", nativeQuery = true)
    List getGonggaobyIp(@Param("ip")String ip);
	
	@Query(value = "select t_user.userip,status,user_gonggao.gonggaoid,t_user.fybm,t_user.fymc from user_gonggao,gonggao,t_user where t_user.id=user_gonggao.userid and gonggao.id=:gonggaoid and user_gonggao.gonggaoid=gonggao.id", nativeQuery = true)
	List getGonggaobyId(@Param("gonggaoid") int gonggaoid);
	
	/*@Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update user_gonggao set checked=:checked where gonggaoid=:gonggaoid",nativeQuery = true)//原生SQL
    Integer updateStutas(@Param("ip")String ip,@Param("checked") String checked,@Param("gonggaoid") int gonggaoid);*/
}
